import tensorflow as tf
from sem_seg.batch_inference import evaluate
from flask import Flask, jsonify, json, request
from flask_cors import *


app = Flask(__name__)
CORS(app, supports_credentials=True)
app.debug = True


@app.route('/uploadFile', methods=['POST'])
def uploadFile():
    file = request.get_data()
    file_obj = json.loads(file)
    print('file_name', file_obj['name'])
    print('file_data', file_obj['data'])
    with tf.Graph().as_default():
        arr_pred = evaluate(file_obj)
        result_pred = {
            'id': file_obj['id'],
            'name': file_obj['name'],
            'arr_pred': arr_pred
        }
    return jsonify(result_pred)


if __name__ == '__main__':
    app.run()
